Batcher's odd–even mergesort is a generic construction devised by Ken Batcher for sorting networks of size O(''n'' (log ''n'')2) and depth O((log ''n'')2), where ''n'' is the number of items to be sorted. Although it is not asymptotically optimal, Knuth concluded in 1998, with respect to the AKS network that "Batcher's method is much better, unless ''n'' exceeds the total memory capacity of all computers on earth!"〔D.E. Knuth. ''The Art of Computer Programming'', Volume 3: ''Sorting and Searching'', Third Edition. Addison-Wesley, 1998. ISBN 0-201-89685-0. Section 5.3.4: Networks for Sorting, pp. 219–247.〕 It is popularized by the second ''GPU Gems'' book,〔http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter46.html〕 as an easy way of doing reasonably efficient sorts on graphics-processing hardware. == Example code ==
The following is an implementation of odd–even mergesort algorithm in Python. The input is a list ''x'' of length a power of 2. The output is a list sorted in ascending order.